<?php
session_start();
include('includes/db/sql.functions.php');
$type = $_REQUEST['type'];
$name = $_REQUEST['name'];
$comments = $_REQUEST['comments'];
$testBy = $_REQUEST['testBy'];
$bb_name = $_GET['bb'];

$errores = array();
$values = array();


if($name == ""){
	$errores["name"]= "Empty name";
}else{
	$values["name"]=$name;
}
if($comments == ""){
	$errores["comments"]= "Empty comments";
}else{
	$values["comments"]=$comments;
}
if($testBy == ""){
	$errores["testBy"]= "There must be tested by someone";
}else{
	$values["testBy"]=$testBy;
}


if($type == "tabs-2"){
	if($targInd == ""){
		$errores["targInd"]= "We need the target inductor";
	}else{
		$values["targInd"]=$targInd;
	}
	if($targInd_species == ""){
		$errores["targInd_species"]= "We need the target inductor specie";
	}else{
		$values["targInd_species"]=$targInd_species;
	}
	if($targInd_fasta == ""){
		$errores["targInd_fasta"]= "We need the target inductor FASTA";
	}else{
		$values["targInd_fasta"]=$targInd_fasta;
	}
}

$_SESSION['addWireForm']['type']=$type;
if(!empty($errores)){
	$_SESSION['addWireForm'][$type]['errores'] = $errores;
}
$_SESSION['addWireForm'][$type]['values'] = $values;

//print_r($errores);
if($errores){
	header("Location:addWire.php#$type");
}else{
	$_SESSION['addWireForm']['errores']="";
	$hws_link="";//a la espera de crearse en el formulario
	if($type == "tabs-1"){
		$type2="EHW";
	}

	if($type == "tabs-2"){
		$type2="RHW";
	}

	if($type == "tabs-3"){
		$type2="SINK";
	}

	if($type == "tabs-2"){
		$query2=add_targProm($targInd, $targInd_species, $targInd_fasta);
		if($query2!=-9){
			$query=add_hws($name, $_REQUEST['bb'],$comments, $hws_link, $testBy, $type2);
			if($query!=-9){
				$query3=add_TP_hws($name,$targInd);
				if($query3!=-9){
					header("Location:genList.php?hwsname=$name");
				}
			}
		}
	}else{
		
		$query=add_hws($name, $_REQUEST['bb'],$comments, $hws_link, $testBy, $type2);
			if($query!=-9){
				header("Location:genList.php?hwsname=$name");
			}
	}



}


?>